package com.meichis.yndms.adapter.RecycleViewItemType;

import android.text.Html;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.meichis.mcsappframework.adapter.recyclerview.base.ItemViewDelegate;
import com.meichis.mcsappframework.adapter.recyclerview.base.ViewHolder;
import com.meichis.yndms.R;
import com.meichis.yndms.model.InspectResult_Detail;

import java.util.ArrayList;

/**
 * Created by pei on 2016/8/24.
 * 默认item
 */
public class FillMode_TextViewDP implements ItemViewDelegate<InspectResult_Detail> {
    private ArrayList<InspectResult_Detail> items;

    public FillMode_TextViewDP(ArrayList<InspectResult_Detail> items) {
        this.items = items;
    }

    @Override
    public int getItemViewLayoutId() {
        return R.layout.fill_mode_text;
    }

    @Override
    public boolean isForViewType(InspectResult_Detail item, int position) {
        return item.getFillMode() != 9;
    }

    @Override
    public void convert(final ViewHolder holder, final InspectResult_Detail item, int position) {
        TextView tv_group = holder.getView(R.id.tv_group);
        if (position == 0) {
            if (!TextUtils.isEmpty(item.getItemGroup())) {
                tv_group.setVisibility(View.VISIBLE);
                holder.setVisible(R.id.v_group, true);
                tv_group.setText(item.getItemGroup());
            } else {
                tv_group.setVisibility(View.GONE);
                holder.setVisible(R.id.v_group, false);
            }
        } else {
            if (!TextUtils.isEmpty(item.getItemGroup()) && !item.getItemGroup().equals(items.get(position - 1).getItemGroup())) {
                tv_group.setVisibility(View.VISIBLE);
                holder.setVisible(R.id.v_group, true);
                tv_group.setText(item.getItemGroup());
            } else {
                tv_group.setVisibility(View.GONE);
                holder.setVisible(R.id.v_group, false);
            }
        }

        holder.setText(R.id.tv_question, String.valueOf(Html.fromHtml(String.valueOf(position + 1) + ". " +
                item.getInspectItemName() +
                (!TextUtils.isEmpty(item.getUnit()) ? "(" + item.getUnit() + ")" : "") +
                (item.getFillMode() == 4 ? "  <font  color=\"#6699FF\">[ 多选 ]</font>" : "") +
                (!TextUtils.isEmpty(item.getSubTitle()) ? "<br/> <font color=\"#8D8D8D\" ><small>" + item.getSubTitle() + "</small></font>" : "")
        )));
        if (item.getFillMode() == 5) {
            holder.setText(R.id.tv_answer, "  " + item.getFillName() + (!TextUtils.isEmpty(item.getRemark()) ? "\n" + item.getRemark() : ""));
        } else {
            holder.setText(R.id.tv_answer, "  " + item.getFillName().replaceAll("\\|", "\n  "));
        }
        holder.getView(R.id.iv_data).setVisibility(item.getFillMode() == 7 ? View.VISIBLE : View.GONE);
    }
}
